﻿using System;
using System.Collections.Generic;
using Contracts.Entities;
using Contracts.Library;

namespace Definition.WebImport
{
    public class TmdbSearchRequest : TmdbRequest
    {
        public IEnumerable<TmdbMovieSearchItem> Search(string title)
        {
            var xmlMovies = GetMoviesElement(title);
            var movies = new List<TmdbMovieSearchItem>();
            
            if (xmlMovies == null)
                return movies;

            //De-Serialization
            return xmlMovies.FromXElement<TmdbSearchMovie>().Movies;
        }

        public override string GetUrl()
        {
            return String.Format("{0}{1}/{2}/{3}/", TmdbApi.Url, TmdbApi.Version, "Movie.search/en/xml", TmdbApi.Key);
        }   
    }
}
